const host='http://localhost:8000'
function btnAdd(){
     console.log('新增');
    location.href = './addOrEite.html'
}
function btnEdit(id){
    location.href = './addOrEite.html?id=' + id
}
function btnDit(id){
   
        console.log('删除');
       
        if (confirm('确认删除吗？')) {
            axios.delete(`${host}/blogs/${id}`).then((res) => {
                // console.log(res);
                let data = res.data;
                if (data.code === 1000) {
                    // 删除成功
                    let tr = document.querySelector(`.blog${id}`)
                    tr.remove()
                } else {
                    // 删除不成功
                    confirm(`${data.msg}`)
                }
    
            })
        }
    
    }
    function btnSave() {
       
        let id = new URLSearchParams(location.search).get('id') || 0
    
        let title = $('input[name=title]').val();
        let author = $('input[name=author]').val();
       
        title = title.trim()
        author = author.trim()
        let obj = {
            title, author
        }
    
        console.log(obj);
    
        if (id > 0) {
           
            axios.put(`${host}/blogs/${id}`, obj).then((res) => {
               
                if (res.data.code === 1000) {
                    location.href = './index.html'
                } else {
                    confirm(res.data.msg)
                }
    
    
            })
        } else {
            // 第二步，请求新增
            axios.post(`${host}/blogs`, obj).then((res) => {
                // 处理返回的各应数据
                // console.log(res);
                if (res.data.code === 1000) {
                    location.href = './index.html'
                } else {
                    confirm(res.data.msg)
                }
    
    
            })
        }
    
    
    
    
    
    }
function btnFt(){
    console.log("过滤")
}

function btnQx(){
     location.href = './index.html'
}
